package com.seahorse.youliao.controller;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.seahorse.youliao.logfilter.Log;
import com.seahorse.youliao.service.FmsPayOrderService;
import com.seahorse.youliao.service.entity.FmsPayOrderDTO;
import com.seahorse.youliao.utils.BeanUtil;
import com.seahorse.youliao.vo.request.FmsPayOrderQueryVO;
import com.seahorse.youliao.vo.request.FmsPayOrderUpdateVO;
import com.seahorse.youliao.vo.response.FmsPayOrderPageInfoVO;
import com.seahorse.youliao.vo.response.FmsPayOrderResponseVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
* describe: 支付订单
* @author : songtqiang
* @date: 2020-03-18 02:20:25.891
**/
@RestController
@Api(value = "FmsPayOrderController",tags = "微信/支付宝 支付订单")
@RequestMapping("fmsPayOrder")
@Validated
public class FmsPayOrderController {
	
    private static final Logger LOGGER = LoggerFactory.getLogger(FmsPayOrderController.class);
    
	@Autowired
    private FmsPayOrderService fmsPayOrderService;
    /**
     * 分页查询
     * @param fmsPayOrderQueryVO 分页查询参数
     * @return 分页参数
     */
    @ApiOperation(value = "分页查询")
    @PostMapping("getPageList")
    public FmsPayOrderPageInfoVO selectPageList(@RequestBody @Valid FmsPayOrderQueryVO fmsPayOrderQueryVO) {
        String info = String.format("The method name[selectPageList] params:%s", fmsPayOrderQueryVO.toString());
        LOGGER.info(info);
        FmsPayOrderDTO fmsPayOrder = BeanUtil.convert(fmsPayOrderQueryVO, FmsPayOrderDTO.class);

        Page<FmsPayOrderResponseVO> page = PageHelper.startPage(fmsPayOrderQueryVO.getPageNum(), fmsPayOrderQueryVO.getPageSize());
        List<FmsPayOrderDTO> fmsPayOrderList = fmsPayOrderService.getList(fmsPayOrder);
        FmsPayOrderPageInfoVO fmsPayOrderPageInfo = new FmsPayOrderPageInfoVO();
        BeanUtils.copyProperties(page.toPageInfo(), fmsPayOrderPageInfo);
        List<FmsPayOrderResponseVO> voList = BeanUtil.convert(fmsPayOrderList, FmsPayOrderResponseVO.class);
        fmsPayOrderPageInfo.setList(voList);

        return fmsPayOrderPageInfo;
    }


    /**
     * 新增商品下单
     * @param payOrderUpdateVO
     * @return
     */
    @Log(type = Log.OperationType.ADD,button = "新增商品下单",menu = "支付订单")
    @ApiOperation(value = "新增商品下单")
    @PostMapping("insert")
    public boolean insert(@RequestBody @Valid FmsPayOrderUpdateVO payOrderUpdateVO){

        return true;
    }

    /**
     * 删除商品下单
     * @param id
     * @return
     */
    @Log(type = Log.OperationType.ADD,button = "删除商品下单",menu = "支付订单")
    @ApiOperation(value = "删除商品下单")
    @PostMapping("delete")
    public boolean delete(@RequestParam(required = true)
                              @ApiParam(name = "id",value = "id",required = true) Long id){

        return true;
    }

    /**
     * 查看商品支付明细
     * @param id
     * @return
     */
    @Log(type = Log.OperationType.ADD,button = "查看商品支付明细",menu = "支付订单")
    @ApiOperation(value = "查看商品支付明细")
    @PostMapping("getPayOrderDetail")
    public boolean getPayOrderDetail(@ApiParam(name = "id",value = "id",required = true)
                                         @RequestParam Long id){

        return true;
    }

}
